﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SecurityDecoder
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void cmddecodestring_Click(object sender, EventArgs e)
        {
            if (txtDecodeString.Text.Trim() == "") return;

            string lines = EncodeDecode.Decrypt(txtDecodeString.Text.Trim(), "St4rtsz9");

            // Write the string to a file.
            System.IO.StreamWriter file = new System.IO.StreamWriter(Application.StartupPath + "\\DecodedData.txt");
            file.WriteLine(lines);

            file.Close();

            MessageBox.Show("Data was correctly decoded!!!!");
        }

        private void cmdgetserial_Click(object sender, EventArgs e)
        {

            InputBoxResult InputBoxRes;

            InputBoxRes = InputBox.Show("Introduce tu ID de técnico especializado!!!", Application.ProductName);

            if (InputBoxRes.ReturnCode == System.Windows.Forms.DialogResult.OK)
            {
                if ( InputBoxRes.Text == "St4rtsz9" )
                {
                    txtserial.Text = "A55Z" + MotherBoardInfo.SerialNumber + "B66Y" + MotherBoardInfo.Product + "C77X" + MotherBoardInfo.Version;
                }
            }
        }

        private void cmdGenerate_Click(object sender, EventArgs e)
        {
            string TempoKey = EncodeDecode.Encrypt( MotherBoardInfo.Product.Trim() + "-" + MotherBoardInfo.Version.Trim()/* + "-" + MotherBoardInfo.SerialNumber*/ , "St4rtsz9");

            StringBuilder mString = new StringBuilder("");
            StringBuilder mEncoded = new StringBuilder();

            mString.AppendLine("Hosting Board: " + MotherBoardInfo.HostingBoard.ToString());
            mString.AppendLine("Install Date: " + MotherBoardInfo.InstallDate);
            mString.AppendLine("Manufacturer: " + MotherBoardInfo.Manufacturer);
            mString.AppendLine("Model: " + MotherBoardInfo.Model);
            mString.AppendLine("Part Number: " + MotherBoardInfo.PartNumber);
            mString.AppendLine("PNP Device ID: " + MotherBoardInfo.PNPDeviceID);
            mString.AppendLine("Primary Bus Type: " + MotherBoardInfo.PrimaryBusType);
            mString.AppendLine("Product: " + MotherBoardInfo.Product);
            mString.AppendLine("Removable: " + MotherBoardInfo.Removable);
            mString.AppendLine("Replaceable: " + MotherBoardInfo.Replaceable);
            mString.AppendLine("Revision Number: " + MotherBoardInfo.RevisionNumber);
            mString.AppendLine("Secundary Bus Type: " + MotherBoardInfo.SecondaryBusType);
            mString.AppendLine("Serial Number: " + MotherBoardInfo.SerialNumber);
            mString.AppendLine("Status: " + MotherBoardInfo.Status);
            mString.AppendLine("System Name: " + MotherBoardInfo.SystemName);
            mString.AppendLine("Version: " + MotherBoardInfo.Version);
            mString.AppendLine(" ");
            mString.AppendLine( Environment.GetFolderPath(Environment.SpecialFolder.System) );
            mString.AppendLine(" ");

            mEncoded.AppendLine(EncodeDecode.Encrypt(MotherBoardInfo.HostingBoard.ToString(), "St4rtsz9"));
            mEncoded.AppendLine(EncodeDecode.Encrypt(MotherBoardInfo.InstallDate, "St4rtsz9"));
            mEncoded.AppendLine(EncodeDecode.Encrypt(MotherBoardInfo.Manufacturer, "St4rtsz9"));
            mEncoded.AppendLine(EncodeDecode.Encrypt(MotherBoardInfo.Model, "St4rtsz9"));
            mEncoded.AppendLine(EncodeDecode.Encrypt(MotherBoardInfo.PartNumber, "St4rtsz9"));
            mEncoded.AppendLine(EncodeDecode.Encrypt(MotherBoardInfo.PNPDeviceID, "St4rtsz9"));
            mEncoded.AppendLine(EncodeDecode.Encrypt(MotherBoardInfo.PrimaryBusType, "St4rtsz9"));
            mEncoded.AppendLine(EncodeDecode.Encrypt(MotherBoardInfo.Product, "St4rtsz9"));
            mEncoded.AppendLine(EncodeDecode.Encrypt(MotherBoardInfo.Removable.ToString(), "St4rtsz9"));
            mEncoded.AppendLine(EncodeDecode.Encrypt(MotherBoardInfo.Replaceable.ToString(), "St4rtsz9"));
            mEncoded.AppendLine(EncodeDecode.Encrypt(MotherBoardInfo.RevisionNumber, "St4rtsz9"));
            mEncoded.AppendLine(EncodeDecode.Encrypt(MotherBoardInfo.SecondaryBusType, "St4rtsz9"));
            mEncoded.AppendLine(EncodeDecode.Encrypt(MotherBoardInfo.SerialNumber, "St4rtsz9"));
            mEncoded.AppendLine(EncodeDecode.Encrypt(MotherBoardInfo.Status, "St4rtsz9"));
            mEncoded.AppendLine(EncodeDecode.Encrypt(MotherBoardInfo.SystemName, "St4rtsz9"));
            mEncoded.AppendLine(EncodeDecode.Encrypt(MotherBoardInfo.Version, "St4rtsz9"));
            mEncoded.AppendLine(" ");
            mEncoded.AppendLine(EncodeDecode.Encrypt( Environment.GetFolderPath(Environment.SpecialFolder.System),"St4rtsz9"));
            mEncoded.AppendLine(" ");

            txtEncodedData.Text = mString.ToString();
            txtEncodedData.Text += mEncoded;

            //return;

            //try
            //{
            //    if (true/*textBox1.Text == "@St4rtsz9@"*/)
            //    {
            //        // Avoid last four digits on final key
            //        txtEncodedData.Text = "" + "F3BA";

            //        string TmpPath = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\SKSMA.log";

            //        string lines = TempoKey;

            //        // Write the string to a file.
            //        System.IO.StreamWriter file = new System.IO.StreamWriter(TmpPath);
            //        file.WriteLine(lines);

            //        file.Close();

            //        txtEncodedData.Text = lines + "A54C";

            //        MessageBox.Show("Felicidades se ha incrustado la llave para la utilización de este paquete!!!");
            //    }
            //    else
            //    {
            //        MessageBox.Show("Password de utileria incorrecto!!!");
            //    }
            //}
            //catch
            //{
            //    MessageBox.Show("Error al generar el archivo de seguridad");
            //}
            
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //if ((DateTime.Now.Year >= 2014) && (DateTime.Now.Month == 12) && (DateTime.Now.Day >= 5) && (DateTime.Now.Day < 7))
            //{
            //    ;
            //}
            //else
            //{
            //    Application.ExitThread();
            //    Application.Exit();
            //}
        }
    }
}
